import { Module } from 'vuex';
import { AppState } from './types';
import { RootState } from '../types';
import { getters } from './getters';
import { actions } from './actions';
import { mutations } from './mutations';
import { CommentType, PlayModel } from '@/model/id-or-enum.model';
import local from '@/utils/local-utils';
import _ from 'lodash';

const state: AppState = {
  userInfo: {},
  prevPath: '/',
  musicUrlList: [],
  isPlaying: true,
  isController: false,
  loginDialogVisible: false,
  nowMusic: {
    index: null,
    id: '',
    nowMusicUrl: '',
    nowName: '',
    nowArtists: [],
    nowImgUrl: '',
    isPlaying: false,
  },
  full: {
    fullTime: null,
    fullMin: '',
    fullSec: '',
  },
  current: {
    currentTime: null,
    currentMin: '',
    currentSec: '',
    value1: null,
  },
  mvId: 0,
  moreMsg: null,
  /**
   *   播放模式, 0代表列表顺序播放，1随机播放，2单曲循环
   */
  playModel: PlayModel.Sequence,
  /**
   *   存储comment页面的来源, 0代表音乐，1代表歌单，2代表专辑，3代表mv
   */
  commentType: CommentType.ToSong,
  /**
   *   存储评论页面头部信息
   */
  commentHeader: null,
};
Object.keys(state).forEach((key: string) => {
  let value = local.get(key);
  if (value != null && typeof value === typeof _.get(state, key)) {
    _.set(state, key, value);
  }
});
const namespaced = true;
export const app: Module<AppState, RootState> = {
  namespaced,
  state,
  getters,
  actions,
  mutations,
};
export default state;
